//
//  ViewController.m
//  DynamicIconDemo
//
//  Created by BaizYi on 2019/1/16.
//  Copyright © 2019 BaiziYI. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property(strong,nonatomic) NSArray  *iconArr;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.iconArr = @[@"晴", @"多云", @"小雨", @"大雨", @"雪"];
}
- (IBAction)changeAppIconAction:(id)sender {
    NSString *iconName = self.iconArr[arc4random() % self.iconArr.count];
    [self setAppIconName:iconName];
}

-(void)setAppIconName:(NSString *)iconName{
    if (![[UIApplication sharedApplication] supportsAlternateIcons]) {
        return;
    }
    [[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"更换图标错误:%@", error);
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
